//
//  MainActivityCell.m
//  Rabbit
//
//  Created by 阿帕 on 2018/11/4.
//  Copyright © 2018年 GCY. All rights reserved.
//

#import "MainActivityCell.h"

@interface MainActivityCell ()
@property (weak, nonatomic) IBOutlet UILabel *zhuangAdressLabel;
@property (weak, nonatomic) IBOutlet UILabel *xieAdressLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *carInfoLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UIButton *telButton;
@property (weak, nonatomic) IBOutlet UILabel *stateLabel;
@property (weak, nonatomic) IBOutlet UILabel *branchNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *loadDetailAddressLab;
@property (weak, nonatomic) IBOutlet UILabel *unloadDetailAddressLab;

@end

@implementation MainActivityCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _telButton.hidden = YES;
    _branchNameLabel.textColor = Dark_TextColor;
    _zhuangAdressLabel.textColor = [UIColor cy_colorWithHexString:@"#434C67"];
    _xieAdressLabel.textColor = [UIColor cy_colorWithHexString:@"#434C67"];
    _nameLabel.textColor = [UIColor cy_colorWithHexString:@"#434C67"];
    _carInfoLabel.textColor = [UIColor cy_colorWithHexString:@"#96A0B9"];
    _loadDetailAddressLab.textColor = Dark_TextColor;
    _unloadDetailAddressLab.textColor = Dark_TextColor;

    _branchNameLabel.font = font(15);
    _zhuangAdressLabel.font = font(14);
    _zhuangAdressLabel.numberOfLines = 2;
    _zhuangAdressLabel.adjustsFontSizeToFitWidth = YES;
    _xieAdressLabel.font = font(14);
    _xieAdressLabel.numberOfLines = 2;
    _xieAdressLabel.adjustsFontSizeToFitWidth = YES;
    _nameLabel.font = font(13);
    _carInfoLabel.font = font(11);
    _carInfoLabel.numberOfLines = 2;
    _loadDetailAddressLab.font = font(12);
    _unloadDetailAddressLab.font = font(12);

}
- (void)setActivityModel:(MainActivityModel *)activityModel {
    NSLog(@"activityModel.lastWeight %@", activityModel.lastWeight);

    _activityModel = activityModel;
    
    [self changeOrderState:activityModel.pushTarget :activityModel.isQuote];
    if(activityModel.createdByName.length == 0) {
        _branchNameLabel.text = @"--";

    }else{
        _branchNameLabel.text = [NSString nullToString:CJStringWithFormat(@"发货企业:%@",activityModel.createdByName)];;
    }
    _zhuangAdressLabel.text = [NSString nullToString:activityModel.shipperAddress];
    _loadDetailAddressLab.text = activityModel.shipperDetailAddress;
    _xieAdressLabel.text = [NSString nullToString:activityModel.consigneeAddress];
    _unloadDetailAddressLab.text = activityModel.consigneeDetailAddress;
    _nameLabel.text = [NSString nullToString:CJStringWithFormat(@"发货人:%@",activityModel.shipperName)];//发货人名称
    
    NSString *notReceivedCount = @"";
    
    if (activityModel.notReceivedCount == 0) {
        notReceivedCount = @"不限车";
    } else {
        notReceivedCount = CJStringWithFormat(@"%ld车",(long)activityModel.notReceivedCount);
    }
    
    NSString *lastWeight = @"";
    
    if ([DCSpeedy isPureInt:activityModel.lastWeight]) {
        lastWeight = activityModel.lastWeight;
    } else {
        lastWeight = CJStringWithFormat(@"%.3f", [activityModel.lastWeight floatValue]);
    }
    
    if (activityModel.isQuote == 1) {
        //允许报价，0-不允许，1-允许
        _carInfoLabel.text = CJStringWithFormat(@"%@ %@ %@%@ %@", activityModel.coalTypeName,  notReceivedCount, lastWeight, activityModel.coalUnitName, [NSString nullToString:activityModel.pushVehicleUse]);
        
    } else {
        _carInfoLabel.text = CJStringWithFormat(@"%@ %.2f%@ %@ %@%@ %@", activityModel.coalTypeName, activityModel.realPrice, activityModel.isTrunkName, notReceivedCount, lastWeight, activityModel.coalUnitName, [NSString nullToString:activityModel.pushVehicleUse]);
    }
    
    [_headImageView setImageWithURL:[NSURL URLWithString:_activityModel.coalName] placeholder:image(@"gcy_img_main_head")];
}


//判断订单状态
- (void)changeOrderState:(NSString *)pushTarget :(NSInteger)IsQuote {
    /*
     pushTarget 不为空，指派
     pushTarget 空，根据 IsQuote，1竞价，0普通
     */
    if ([DCSpeedy isBlankString:pushTarget] == YES) {
        if (IsQuote == 1) {
            _stateLabel.text = @"竞价单";
            _stateLabel.textColor = [UIColor colorWithHexString:@"#2D7DF6"];
            _stateLabel.backgroundColor = [UIColor colorWithHexString:@"#E7F0FF"];
        } else if (IsQuote == 0) {
            _stateLabel.text = @"普通单";
            _stateLabel.textColor = [UIColor colorWithHexString:@"#04B715"];
            _stateLabel.backgroundColor = [UIColor colorWithHexString:@"#EBF9ED"];
        }
    } else {
        _stateLabel.text = @"指派单";
        _stateLabel.textColor = [UIColor colorWithHexString:@"#EF8221"];
        _stateLabel.backgroundColor = [UIColor colorWithHexString:@"#FEF4EC"];
    }
}

- (IBAction)telClick:(id)sender {
    CALL_PHONE(_activityModel.consigneePhone);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
